//
//  JsonLoader.h
//  roborobo
//
//  Created by Berend Weel on 6/26/13.
//
//

#ifndef roborobo_JsonLoader_h
#define roborobo_JsonLoader_h

#include <Box2D/Box2D.h>
#include <vector>
#include <map>
#include <boost/property_tree/ptree.hpp>

struct ShapeModel {
    enum Type {POLYGON, CIRCLE};
    
    std::vector<b2Vec2> vertices;
    Type type;
    bool isCLosed = false;
};

struct PolygonModel {
    std::vector<b2Vec2> vertices;
};

struct CircleModel {
    b2Vec2 center;
    float radius;
};

struct RigidBodyModel {
    std::string name;
    std::string imagePath;
    b2Vec2 origin;
    std::vector<PolygonModel*> polygons;
    std::vector<CircleModel*> circles;
};

struct Model {
    std::map<std::string,RigidBodyModel*> rigidBodies;
};

class BodyEditorLoader {
    
public:
    BodyEditorLoader(std::string str);
    void attachFixture(b2Body *body, std::string name, b2FixtureDef *fd, float scale);
    std::string getImagePath(std::string name);
    b2Vec2 *getOrigin(std::string name, float scale);
    Model *getInternalModel();
    RigidBodyModel* readRigidBody(boost::property_tree::ptree bodyElem);
    
    Model *readJson(std::string str);
    
private:
    // Reusable stuff
    Model *model;
};


#endif
